import * as TYPES from "../action-types";
import Dog from "@/typings/dog";
import {message} from "antd";
import {push} from "connected-react-router";

export default{
    addCartItem(dog:Dog){
        return function(dispatch:any){
            dispatch({
                type:TYPES.ADD_CART_ITEM,
                payload:dog
            });
            message.info(`添加【${dog.category}】成功`);
        }
    },

    removeCartItem(id:string){
        return{
            type:TYPES.REMOVE_CART_ITEM,
            payload:id
        }
    },

    clearCartItems(){
        return{
            type:TYPES.CLEAR_CART_ITEMS
        }
    },

    changeCartItemCount(id:string,count:number){
        return{
            type:TYPES.CHANGE_CAR_ITEM_COUNT,
            payload:{
                id,
                count
            }
        }
    },

    changeCheckedCartItems(checkedIds:string[]){
        return {
            type:TYPES.CHANGE_CHECKED_CART_ITEMS,
            payload:checkedIds
        }
    },

    settle(){
        return (dispatch:any)=>{
            dispatch({
                type:TYPES.SETTLE
            });
            dispatch(push("/"));
        }
    }
}